Skip to content

feat: add bitwise operations AND, OR, XOR, NOT, LSHIFT, RSHIFT#13

Merged
tetsuo-cpp merged 1 commit intocanonfrom
feat/bitwise-ops
Feb 15, 2026
Merged

feat: add bitwise operations AND, OR, XOR, NOT, LSHIFT, RSHIFT#13
tetsuo-cpp merged 1 commit intocanonfrom
feat/bitwise-ops

Conversation

@tetsuo-cpp
Copy link
Owner

@tetsuo-cpp tetsuo-cpp commented Feb 15, 2026

Summary

  • Add six bitwise ops (AND, OR, XOR, NOT, LSHIFT, RSHIFT) to the Forth dialect for GPU kernel tiling and address alignment
  • Binary ops reuse BinaryArithOpConversion; NOT uses a unary XOR-with-(-1) pattern
  • RSHIFT uses arith::ShRUIOp (logical/unsigned shift)

Closes #3

Test plan

  • Translation test: test/Translation/Forth/bitwise-ops.forth
  • Conversion test: test/Conversion/ForthToMemRef/bitwise.mlir
  • All 35 tests pass (cmake --build build --target check-warpforth)

@tetsuo-cpp
Copy link
Owner Author

Code Review

Overview

Adds 6 bitwise operations (AND, OR, XOR, NOT, LSHIFT, RSHIFT) across the full compiler stack: dialect definition, parser, MemRef conversion, and tests.

Correctness

  • Binary ops (AND, OR, XOR, LSHIFT, RSHIFT): Correctly reuse BinaryArithOpConversion template — no new code to get wrong. arith op mappings are correct (AndIOp, OrIOp, XOrIOp, ShLIOp, ShRUIOp).
  • NOT (unary): XOR with -1 (all bits set) is the correct bitwise complement for i64. Pattern correctly follows ZeroEqOpConversion structure — loads at SP, operates, stores back, SP unchanged.
  • RSHIFT uses ShRUIOp (unsigned/logical): Correct per issue spec. Standard Forth RSHIFT is defined as logical shift.
  • Parser: Words placed correctly after MOD, before @. Case-insensitive matching inherited from existing toUpperCase in the lexer.

Style & Conventions

  • Op definitions follow the exact same boilerplate as existing arithmetic ops — consistent.
  • Section header // Bitwise operations. with LLVM-style separators matches project convention.
  • Stack effect comments in .td descriptions follow the ( input -- output ) pattern.
  • clang-format already applied (formatting diff in patterns.add is cosmetic only).

Test Coverage

  • Translation test covers all 6 words with full SSA chaining verification.
  • Conversion test checks each op lowers to the correct arith.* op, including NOT's arith.constant -1 + arith.xori pattern.
  • No pipeline (end-to-end) test, but this is consistent with how arithmetic and comparison ops were added — pipeline tests exercise combinations, not individual ops.

No Issues Found

Clean PR. The implementation is minimal and mechanical — 5 of 6 ops are one-line type aliases, the 6th (NotOpConversion) is a straightforward 10-line struct following an established pattern. No risks identified.

@tetsuo-cpp tetsuo-cpp merged commit 4afa167 into canon Feb 15, 2026
1 check passed
@tetsuo-cpp tetsuo-cpp deleted the feat/bitwise-ops branch February 15, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bitwise operations: AND OR XOR NOT LSHIFT RSHIFT

1 participant